import React from 'react'
import '@/assets/css/login.module.css'


const Login = () => {
    const Footer = () => {
        return (
            <>
                <React.UI.Button type='submit' color='primary' size='large'>
                    注册登录
                </React.UI.Button>
            </>
        )
    }


    const OnSubmit = async (values: {
        mobile: string,
        password: string
    }) => {
        const result = await React.Http.post('/business/login', values);

        if (result.code === 1) {
            React.success(result.msg, () => {
                // 把登录信息存储cookie
                React.Cookies.save('business', result.data, { path: '/' });
                React.business = result.data; // 更新全局business对象
                React.navigate(result.url);
            });
        } else {
            React.fail(result.msg);
        }
    }

    return (
        <>
            {/* <div className={styles.headers}>
                <div className={styles.userinfo}>
                    <div className={styles.avatar}></div>
                </div>
                <div className={styles.corrugated}>
                    <div className={`${styles.wave_top} ${styles.wave_item}`}></div>
                    <div className={`${styles.wave_middle} ${styles.wave_item}`}></div>
                </div>
            </div> */}
            <div className='login'>
                <React.UI.Form
                    footer={<Footer />}
                    onFinish={OnSubmit}

                >
                    <React.UI.Form.Item
                        name='mobile'
                        label='手机号'
                        rules={[
                            { required: true, message: '手机号不能为空' },
                            { pattern: /^1[3-9]\d{9}$/, message: '手机号格式错误' }
                        ]}
                    >
                        <React.UI.Input placeholder='请输入手机号'></React.UI.Input>
                    </React.UI.Form.Item>
                    <React.UI.Form.Item
                        name='password'
                        label='密码'
                        rules={[
                            { required: true, message: '密码不能为空' },
                        ]}
                    >
                        <React.UI.Input type='password' placeholder='请输入密码'></React.UI.Input>
                    </React.UI.Form.Item>
                </React.UI.Form>
            </div>
        </>
    )
}

export default Login;